package com.lang.teacher.service.imp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import com.asiainfo.crm.core.base.BaseService;
import com.asiainfo.crm.core.common.BaseData;
import com.asiainfo.crm.core.common.BeanFactory;
import com.asiainfo.crm.core.exception.BusinessException;
import com.asiainfo.crm.core.ibatis.CommonDao;
import com.asiainfo.crm.system.service.BusiRecordService;
import com.asiainfo.crm.core.web.PageObject;
import com.lang.MyBaseData;
import com.lang.teacher.dao.TeacherDao;
import com.lang.teacher.model.Teacher;

public class TeacherServiceImp extends BaseService implements com.lang.teacher.service.TeacherService{
	private TeacherDao teacherDao;

	private CommonDao commonDao;

	private BusiRecordService busiRecordService;

	public Teacher getTeacher(String teacherid) throws BusinessException {
		return teacherDao.getTeacher(teacherid);
	}

	public List getTeachers(Map condition) throws BusinessException {
		return teacherDao.getTeachers(condition);
	}

	public List getTeachers(PageObject po) throws BusinessException {
		return teacherDao.getTeachers(po);
	}

	public void addTeacher(Teacher obj) throws BusinessException {
//		obj.setTeacherid(teacherid);
		obj.setTeacherid(System.currentTimeMillis()+"");
		teacherDao.insertTeacher(obj);

//		Integer busisn = commonDao.getSequence("SEQ_BUSISN");
	}

	public void editTeacher(Teacher obj) throws BusinessException {
//		Integer busisn = commonDao.getSequence("SEQ_BUSISN");
		Map mpData = new HashMap();
//		mpData.put("busisn", busisn);
		mpData.put("optr_type", OPTR_TYPE_EDIT);
		mpData.put("teacherid", obj.getTeacherid());
//		teacherDao.insertTeacherHis(mpData);

		teacherDao.updateTeacher(obj);
	}

	public void removeTeachers(Map condition) throws BusinessException {
//		Integer busisn = commonDao.getSequence("SEQ_BUSISN");
//		condition.put("busisn", busisn);
		condition.put("optr_type", OPTR_TYPE_DELETE);
//		teacherDao.insertTeacherHis(condition);
		teacherDao.deleteTeachers(condition);
	}
	
	@SuppressWarnings("unchecked")
	private List getObjs(String sqlId){
		List returnMe = new ArrayList();
		commonDao = (CommonDao) BeanFactory.getBean("commonDao");
		List relationSelect = commonDao.getRelationSelect(sqlId, new HashMap());
		for (Iterator itor = relationSelect.iterator(); itor.hasNext();) {
			BaseData bd = (BaseData) itor.next();
			returnMe.add(new MyBaseData(bd));
		}
		return returnMe;
	}
	
	public List getTeachers(){
		return getObjs("get_teacher");
	}
	
	public List getClasses(){
		return getObjs("get_class");
	}
	
	public List getCourses(){
		return getObjs("get_course");
	}

	public CommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	public TeacherDao getTeacherDao() {
		return teacherDao;
	}

	public void setTeacherDao(TeacherDao teacherDao) {
		this.teacherDao = teacherDao;
	}

	public BusiRecordService getBusiRecordService() {
		return busiRecordService;
	}

	public void setBusiRecordService(BusiRecordService busiRecordService) {
		this.busiRecordService = busiRecordService;
	}
}

